<!--
 * @Author: your name
 * @Date: 2020-12-18 16:08:34
 * @LastEditTime: 2020-12-22 16:34:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \intelligent-agriculture-identification-management-system_-ui\src\pages\Article\article.vue
-->
<!--
  功能：功能描述
  作者：wwk
  邮箱：140775665@qq.com
  时间：2020年12月18日 09:10:34
  版本：v1.0
  修改记录：
  修改内容：
  修改人员：
  修改时间：
-->
<template>
  <div class='btns'>
    <el-form size="small" inline style="text-align:center">
        <el-form-item label="" >
          <el-input placeholder="请输入名称" v-model="param.title">
  </el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="loadArticle()">搜索</el-button>
                    <el-button size="small" @click="toAddHandler" type="primary"><i class="el-icon-upload el-icon--right">
                      </i> 新增
                      </el-button>
                      <el-button size="small" type="primary" @click="downloadHandler">导出</el-button>

        </el-form-item>
      </el-form>
  <!--表格—-->
    <el-table :data="articles" style="width: 100%" >
      <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="内容">
              <span>{{ props.row.content }}</span>
            </el-form-item>
        </el-form>
         </template>
      </el-table-column>
      <el-table-column label="id" prop="id" align="center" ></el-table-column>
      <el-table-column label="名称" prop="title" align="center"></el-table-column>

       <el-table-column label="图片" prop="cover" align="center" width="140">
         <template slot-scope="scope">
          <br>
          <div style="width:120px;border-radius:10px;height:100px;over-flow:hidden">
            <img :src="scope.row.cover" alt="" style="width:100%">
          </div>
        </template>
       </el-table-column>
       
        <el-table-column label="状态" prop="status" align="center"></el-table-column>
         <el-table-column label="时间" prop="publishTime" align="center"></el-table-column>
         
    <el-table-column label="操作" width="100" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button size="mini" @click="editHandler(scope.row)"  type="primary" icon="el-icon-edit" circle ></el-button >
          <el-button  size="mini" @click="deleteHandler(scope.row)" type="danger" icon="el-icon-delete" circle></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import{del,post, get} from '@/utils/request'
export default {
  // 组件名称
  data(){
    return {
      src: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg',
      // 参数，用于保存检索的参数
      param:{},
      // 组件模板中需要的数据
      articles:[],
    };
  },
  // 方法或者js的事件处理函数
  methods:{
    //导出事件方法
    downloadHandler(){
 window.location.href="http://8.131.68.179:9999/cms_article/download?title"+this.param.title;
    },
    // 修改事件处理函数
    editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/article/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
    // 删除事件处理函数
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/cms_article/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadArticle;
        });
      });
    },
    // 跳转
    toAddHandler(){
      this.$router.push("/article/create")
    },
    // 查询后台中的文章信息
    loadArticle(){
      let url = "http://8.131.68.179:9999/cms_article/select"
      get(url,this.param).then(resp => {
        this.articles = resp.data;
      })
    },

  },
  // 页面加载的时候会执行的方法
  created(){
    this.loadArticle();
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: .5em;
}
</style>